package main

import (
	"context"
	"fmt"
	"log"
	"os"

	"github.com/mark3labs/mcp-go/mcp"
	"github.com/mark3labs/mcp-go/server"
)
// https://mp.weixin.qq.com/s/35ougfW9Jf8S0lMmiwG9Rw
func main() {
	// 创建 MCP 服务器
	mcpServer := server.NewMCPServer(
		"test-server",
		"1.0.0",
		server.WithToolCapabilities(true),
	)

	// 添加资源处理函数
	mcpServer.AddResource(
		mcp.NewResource(
			"docs://readme",
			"Project README",
			mcp.WithResourceDescription("The project's README file"),
			mcp.WithMIMEType("text/markdown"),
		),
		func(ctx context.Context, request mcp.ReadResourceRequest) ([]mcp.ResourceContents, error) {
			// 读取 README 文件内容
			content, err := os.ReadFile("README.md")
			if err != nil {
				return nil, err
			}
			// 这里简单返回示例内容，实际可替换为读取文件逻辑
			return []mcp.ResourceContents{
				mcp.TextResourceContents{
					URI:      "docs://readme",
					MIMEType: "text/markdown",
					Text:     string(content),
				},
			}, nil
		},
	)

	// 创建 Streamable HTTP 服务器
	httpServer := server.NewStreamableHTTPServer(mcpServer)

	// 启动服务器
	fmt.Println("Starting server on :8888...")
	if err := httpServer.Start(":8888"); err != nil {
		log.Fatalf("Failed to start server: %v", err)
	}
}
